fix: handle double quotes inside single-quoted GYP strings#3346
Conversation
parseConfigGypi() converted single quotes to double quotes with a bare `config.replace(/'/g, '"')`, which produced invalid JSON when a single-quoted string contained double-quote characters, such as the GYP condition strings used by native addons (e.g. `'OS=="win"'`). Convert each single-quoted string individually and escape the double quotes inside it instead. Fixes: nodejs#3333 Signed-off-by: Paul Bouchon <mail@bitpshr.net>
3b1abb1 to
cf18d58
Compare
|
Rebased this onto main to pick up the undici 8.7.0 fix from #3345, which looks like what was causing the Windows + Node 26 @legendecas the CI run is sitting in |
There was a problem hiding this comment.
In real world, config.gypi is actually a valid JSON since nodejs/node#60794, see: https://github.com/nodejs/node/blob/db3a8d866a8b71a295e2f0ea7176811c3ac918fb/configure.py#L2918-L2920
This parseConfigGypi method is a limited subset dedicated for config.gypi. I'd prefer to have a real-world reproduction, for example, node-gyp rebuild with a binding.gyp.
Fixes #3333.
parseConfigGypi()converted single quotes to double quotes with a bareconfig.replace(/'/g, '"'), which produced invalid JSON whenever a single-quoted string contained"(e.g. GYP condition strings like'OS=="win"', used by native addons such as canvas). It now converts each single-quoted string individually and escapes the double quotes inside it. Added a regression test.